package com.example.newsapp.ui.components.pictureComponent

import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import com.example.newsapp.data.list.imageList.imageUrls
import com.example.newsapp.data.`object`.PictureState
import com.example.newsapp.ui.navigation.PictureNavigation
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@Composable
fun PictureList(modifier: Modifier = Modifier) {
    var scope = rememberCoroutineScope()

    SwipeRefresh(
        state = rememberSwipeRefreshState(PictureState.isRefresh),
        onRefresh = {
            scope.launch {
                PictureState.isRefresh = true
                delay(2000)
                imageUrls.shuffle()
                PictureState.keyRefresh = true
                PictureState.isRefresh = false
            }
        }
    ) {
        // 图片导航
        PictureNavigation()
    }
}